package dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Utils
{
    private static final String DATE_FORMAT_NOW = "yyyy-MM-dd";
    public static String checkAvailable(int state)
    {
	String result = null;
	switch (state)
	{
	    case 0:
		result = "Yes";
		break;
	    case 1:
		result = "No";
		break;
	}
	return result;
    }

    public static String calculateReturnDate(int period)
    {
	Calendar now = Calendar.getInstance();
	now.add(Calendar.DATE, period);
	SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT_NOW);
	String returnDate = df.format(now.getTime());
	return returnDate;
    }

    public static boolean validateReturnDate(String expectedRetunDate,
	    int period)
    {
	Calendar maxReturnDate = Calendar.getInstance();
	maxReturnDate.add(Calendar.DATE, period);
	SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT_NOW);
	Date returnDate = null;
	try
	{
	    returnDate = df.parse(expectedRetunDate);
	}
	catch (ParseException e)
	{
	    System.err.println(e.getMessage());
	}
	if (returnDate != null && returnDate.getTime() <= maxReturnDate.getTimeInMillis())
	{
	    return true;
	}
	return false;

    }
}
